<!--
/*
#################################################################################
#
# Copyright (c) 2006 Michigan State University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#################################################################################

#################################################################################
#
#	Author:
#		Nathan Collins <npcollins@gmail.com>
#
#################################################################################
*/

/* make a request object */
function makeRequestObject() {
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return http_request;
}

/* end */

/* replace element with given text/html */

function updateElement(elemName, updateText) {
	document.getElementById(elemName).innerHTML = updateText;
}

/* end */

/* start ajax Expand */

function sendExpand(toSend, resnum, terms) {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?expand='+toSend+'&r=' + resnum + '&s='+terms);
	ajax.onreadystatechange = function() { recvExpand(ajax, resnum); }
	ajax.send(null);
}

function recvExpand(ajax, resnum) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement(resnum, response);
	}
}

/* end ajax Expand */

/* start ajax Shrink */

function sendShrink(toSend, resnum, terms) {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?shrink='+toSend+'&r=' + resnum + '&s='+terms);
	ajax.onreadystatechange = function() { recvShrink(ajax, resnum); }
	ajax.send(null);
}

function recvShrink(ajax, resnum) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement(resnum, response);
	}
}

/* end ajax Shrink */

/* start ajax Remember */

function sendRemember() {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?remember=1');
	ajax.onreadystatechange = function() { recvRemember(ajax); }
	ajax.send(null);
}

function recvRemember(ajax) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('remembermaster', response);
		addBorder();
		swapArrow();
	}
}

/* end ajax Remember */

/* start ajax History */

function sendHistory() {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?history=1');
	ajax.onreadystatechange = function() { recvHistory(ajax); }
	ajax.send(null);
} 

function recvHistory(ajax) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('historyFloat', response);
		/* bit of a hack - thing is, history doesnt even need to be ajax */
		/* sendRemember(); */ /* should no longer be needed */
	}
}

/* end ajax History */

/* start ajax Suggest */
function sendSuggestDir(parentHash) {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?suggestdir=' + parentHash);
	ajax.onreadystatechange = function() { recvSuggestDir(ajax); }
	ajax.send(null);
}

function recvSuggestDir(ajax) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('parentSelector', response);
	}
}

/* end ajax Suggest */

/* start ajax Accept/Reject */

function sendAR(recID,ar) {
	var ajax = makeRequestObject();
	ajax.open('GET', 'ajax.py?r=' + recID + '&ar=' + ar);
	ajax.onreadystatechange = function() { recvAR(ajax, recID) };
	ajax.send(null);
}

function recvAR(ajax, recID) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('subact'+recID, response);
	}
}

/* end ajax Accept/Reject */

//-->
